const indexListMix = {
	data() {
		return {
			winHeight: 0,
			scrollViewId: '',
			indexBarHeight: 0, // 索引表高度
			indexBarItemHeight: 0, // 索引表子项的高度
			titleHeight: 0, // 索引二字距离窗口顶部的高度
			touchmove: false, // 是否在索引表上滑动
			touchmoveIndex: -1, // 滑动到某个index
		};
	},
	created() {
		const that = this;
		uni.getSystemInfo({
			success: function(res) {
				let winHeight = res.windowHeight;
				let barHeight = that.top != 0 ? uni.upx2px(700) : winHeight - uni.upx2px(204);
				that.winHeight = winHeight;
				that.indexBarHeight = barHeight;
				that.indexBarItemHeight = barHeight / 25;
				that.titleHeight = uni.upx2px(that.top != 0 ? 0 : 132);
			}
		});
	},
	methods: {
		touchStart(e) {
			this.touchmove = true;
			let pageY = e.touches[0].pageY;
			let index = Math.floor((pageY - this.titleHeight - this.top - this.indexListTop) / this.indexBarItemHeight);
			let item = this.list[index];
			if (item) {
				this.scrollViewId = item.letter;
				this.touchmoveIndex = index;
			}
		},
		touchMove(e) {
			let pageY = e.touches[0].pageY;
			let index = Math.floor((pageY - this.titleHeight - this.top - this.indexListTop) / this.indexBarItemHeight);
			let item = this.list[index];
			if (item) {
				this.scrollViewId = item.letter;
				this.touchmoveIndex = index;
			}
		},
		touchEnd() {
			this.touchmove = false;
			this.touchmoveIndex = -1;
		},
		touchCancel() {
			this.touchmove = false;
			this.touchmoveIndex = -1;
		}
	}
};

export default indexListMix;